using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CollegeShop.Infrastructure.Entities.Repository;

namespace CollegeShop.Infrastructure.Entities.Entity
{
    public class Orderdetail : IAccessible<T_Orderdetail, Orderdetail>, ILogicEntity<T_Orderdetail, Orderdetail>
    {
        public int ID { get; set; }

        public int OrderID { get; set; }

        public int GoodsID { get; set; }

        public string GoodsName { get; set; }

        public decimal GoodsPrice { get; set; }

        public int GoodsAmount { get; set; }

        #region extend
        public Order OrderInfo { get; set; }
        public Goods Goods { get; set; }
        #endregion

        protected override void Covariant(T_Orderdetail model)
        {
            if (model != null)
            {
                    this.ID = model.ID;
                    this.OrderID = model.OrderID;
                    this.GoodsID = model.GoodsID;
                    this.GoodsName = model.GoodsName;
                    this.GoodsPrice = model.GoodsPrice;
                    this.GoodsAmount = model.GoodsAmount;
            }
}
        protected override T_Orderdetail Inverter(Orderdetail model)
        {
            if (model != null)
            {
                return new T_Orderdetail()
                {
                    ID = model.ID,
                    OrderID = model.OrderID,
                    GoodsID = model.GoodsID,
                    GoodsName = model.GoodsName,
                    GoodsPrice = model.GoodsPrice,
                    GoodsAmount = model.GoodsAmount,
                };
            }
            return null;
        }
        public Orderdetail Set(T_Orderdetail dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public Orderdetail LoadOrder(T_Order order)
        {
            this.OrderInfo = new Order().Set(order);
            return this;
        }
        public Orderdetail LoadGoods(T_Goods goods,T_Resource resource)
        {
            this.Goods = new Goods().Set(goods).LoadResource(resource);
            return this;
        }
    }
}
